#include <cstdio>
#include <cstring>

int main( )
{
    int i, j, ans, t;
    char s[ 20 ];
    while ( scanf("%s", s) != EOF )
    {
        i = 0;
        s[ strlen( s ) - 1 ]--;
        for ( i = strlen( s ) - 1; i >= 0; i-- )
            if ( s[ i ] < '0' )
            {
                s[ i ] = '9';
                s[ i - 1 ]--;
            }
        for ( i = 0; i < strlen( s ); i++ )
        {
            if ( s[ i ] > '3' )
            {
                while ( i < strlen( s ) )
                {
                    s[ i ] = '3';
                    i++;
                }
            }
        }
        if ( s[ strlen( s ) - 1 ] == '3' )
            s[ strlen( s ) - 1 ] = '2';
        ans = s[ strlen( s ) - 1 ] - '0';
        t = 3;
        for ( i = strlen( s ) - 2; i >= 0; i-- )
        {
            ans += ( s[ i ] - '0' ) * t;
            t *= 4;
        }
        printf("%d\n", ans + 1);
    }
    return 0;
}
